package com.qire.manhua.view.adapter.pager;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.qire.common.widget.adapter.pager.BasePagerAdapter;
import com.qire.manhua.R;
import com.qire.manhua.databinding.LayoutVipInstructionsBinding;

import java.util.ArrayList;

import androidx.annotation.Nullable;

public class VipInstructionsAdapter extends BasePagerAdapter {

    private PageItem[] pageItems = {
      new PageItem(2, R.drawable.app_vip_instructions_pic_discount_head, R.drawable.app_vip_instructions_pic_discount_body, "专享折扣"),
      new PageItem(2, R.drawable.app_vip_instructions_pic_free_head, R.drawable.app_vip_instructions_pic_free_body, "整本限免"),
      new PageItem(2, R.drawable.app_vip_instructions_pic_xmyd_head, R.drawable.app_vip_instructions_pic_xmyd_body, "限免阅读"),
      new PageItem(2, R.drawable.app_vip_instructions_pic_gift_head, R.drawable.app_vip_instructions_pic_gift_body, "会员礼包"),
      new PageItem(2, R.drawable.app_vip_instructions_pic_zstb_head, R.drawable.app_vip_instructions_pic_zstb_body, "专属图标"),
      new PageItem(2, R.drawable.app_vip_instructions_pic_csdm_head, R.drawable.app_vip_instructions_pic_csdm_body, "彩色弹幕"),
    };

    public VipInstructionsAdapter() {
        super(new ArrayList<>(6));
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return pageItems[position].title;
    }

    public VipInstructionsAdapter initView(Context context) {
        for(PageItem pageItem : pageItems) {
            switch (pageItem.type) {
                case 1:
                    mListViews.add(buildImageView(pageItem,context));
                    break;
                case 2:
                    mListViews.add(buildLayout(pageItem,context));
                    break;
            }
        }
        notifyDataSetChanged();
        return this;
    }

    private View buildImageView(PageItem pageItem, Context context) {
        ImageView imageView = new ImageView(context);
        imageView.setImageResource(pageItem.headRid);
        return imageView;
    }
    private View buildLayout(PageItem pageItem, Context context) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        LayoutVipInstructionsBinding binding = LayoutVipInstructionsBinding.inflate(layoutInflater);
        binding.setPageItem(pageItem);
        return binding.getRoot();
    }

    public class PageItem {

        public final int type;
        public final int headRid;
        public final int bodyRid;
        public final String title;

        private PageItem(int type, int headRid, int bodyRid, String title) {
            this.type       = type;
            this.headRid    = headRid;
            this.bodyRid    = bodyRid;
            this.title      = title;
        }
    }

}
